<%--
  Created by IntelliJ IDEA.
  User: zxw
  Date: 2021/3/12
  Time: 18:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>部门信息</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="layui/layui.js"></script>
</head>
<!-- L2Dwidget.js L2D网页动画人物 -->
<script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script>
<script>
    L2Dwidget.init({
        "model": { "jsonPath":"https://unpkg.com/live2d-widget-model-koharu@1.0.5/assets/koharu.model.json", "scale": 1, "hHeadPos":0.5, "vHeadPos":0.618 },
        "display": { "position": "right", "width": 250, "height": 300, "hOffset":0, "vOffset": 0 },
        "mobile": { "show": true, "scale": 0.5 },
        "react": { "opacityDefault": 0.7, "opacityOnHover": 0.2 }
    });
</script>
<body>
<div style="margin: 0 43% ;color: #4E5465;font-size: 50px " >部门信息</div>
<div id="aaa" style="display: none;">
    <table class="layui-hide" id="showdept" lay-filter="showdept"></table>
</div>

<form class="layui-form" action="" lay-filter="formData" id="formData" style="display: none">

    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="text" name="deptid" style="display: none" lay-verify="title" id="id" autocomplete="off"
                   readonly="readonly" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-inline">
            <input type="text" name="dept"    lay-verify="title" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门简介</label>
        <div class="layui-input-inline">
            <input type="text" name="remark" lay-verify="title"  autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否启用</label>
        <div class="layui-input-inline">
            <select name="status">
                <option value="">请选择</option>
                <option value="1">启用</option>
                <option value="0">关闭</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="submitForm">立即提交</button>
        </div>
    </div>
</form>
<div class="layui-btn-group demoTable">
    <button class="layui-btn" data-type="addDept">新增部门</button>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">部门详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="stop">修改部门</a>

</script>


<script type="text/html" id="status">
    {{#  if(d.status ==1){ }}
    <button class="layui-btn layui-btn-sm">启用</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-sm layui-btn-danger">停用</button>
    {{#  } }}
</script>

<script>
    layui.use(['table', 'jquery', 'form'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var form = layui.form;
        $(function () {
            showTable();
        });
        function showTable() {
            table.render({
                elem: '#test'
                , url: '${pageContext.request.contextPath}/dept/show'
                , cellMinWidth: 80
                , defaultToolbar: ['filter', 'exports', 'print']
                , cols: [[
                    {field: 'deptid', title: '部门ID', width: 100, unresize: true, sort: true}
                    , {field: 'dept', title: '部门名称'}
                    , {field: 'remark', title: '部门简介'}
                    , {field: 'username', title: '部门领导'}
                    , {field: 'status', title: '部门状态',templet: '#status'}
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo'}
                ]]
                , id: 'testReload'
                ,page:true
                ,limit:10
                ,limits:[10,20,30]
            });
        }
        var $ = layui.$, active = {
            addDept: function () {
                $("#formData")[0].reset();
                $("#name").removeAttr("readonly");
                layer.open({
                    type: 1
                    , title: '添加部门'
                    , offset: 'auto'
                    , area: ['30%', '60%']
                    , content: $('#formData')
                    , anim: 1

                });
            }
        };

        //表单提交
        form.on('submit(submitForm)', function (data) {
            $.ajax({
                type: 'post',
                url: '${pageContext.request.contextPath}/dept/add',
                data: data.field,
                success: function (result) {
                    layer.closeAll();
                    if (result.code == 1) {
                        showTable();
                        layer.msg(result.msg);
                    } else {
                        layer.msg(result.msg);
                    }

                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });



        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        table.on('tool(test)', function (obj) {
            var data = obj.data;
            var aaa = data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 1,
                    title: data.dept+"部详情",
                    fixed: true,
                    resize: false,
                    moveOut: true,
                    totalRow: true,
                    offset: 'auto',
                    area: ['950px', '400px'],
                    content: $("#aaa"),
                    success: function () {
                        table.render({
                            id: 'idSc',
                            elem: '#showdept'
                            , method: 'post'
                            , url: '${pageContext.request.contextPath}/dept/deptUser?deptid='+data.deptid
                            , toolbar: '#toolbarDemo1'
                            , title: '用户数据表'
                            , totalRow: true
                            , cols: [[
                                {field: 'deptid', title: '部门ID', unresize: true, sort: true}
                                , {field: 'dept', title: '部门名称'}
                                , {field: 'remark', title: '部门简介'}
                                , {field: 'username', title: '部门人员'}
                            ]]
                            , page: false
                        });
                    }
                });

            } else if (obj.event === 'stop') {
                form.val('formData',data);
                layer.open({
                    type: 1
                    , title: '修改部门'
                    , offset: 'auto'
                    , area: ['30%', '60%']
                    , content: $('#formData')
                    , anim: 1
                });
            }

    });

    })


</script>
</body>
</html>
